function fh() {
    location.href = "../../li_meng/GXWuLiaoSheJi(2).html";
}

$(function () {
    WuLiao();
    Time();
})

function Time() {
    var time = new Date();
    var y = time.getFullYear();
    var mon = time.getMonth() + 1; //0-11
    var d = time.getDate();
    var h = time.getHours();
    var m = time.getMinutes();
    var s = time.getSeconds();
    $("#date").val(y + "-" + mon + "-" + d + " " + h + ":" + m + ":" + s);
}

function WuLiao() {
    let WuLiaoMde=JSON.parse(localStorage.getItem("WuLiaoMde"));
    $.ajax({
        type: "post",
        url: "/Dmoduledetails.do/ChaWuLiao",
        data: {productid: WuLiaoMde.productid},
        success: function (data) {
            let tr = "<tr>\n" +
                "      <th>序号</th>\n" +
                "      <th>物料名称</th>\n" +
                "      <th>物料编号</th>\n" +
                "      <th>描述</th>\n" +
                "      <th>设计数量</th>\n" +
                "      <th>可用数量</th>\n" +
                "      <th>单位</th>\n" +
                "      <th>单价(元)</th>\n" +
                "      <th>本工序数量</th>\n" +
                "      </tr>";
            let tr1 = ""
            $.each(data, function (index, item) {
                tr1 += "<tr>\n" +
                    "       <td>" + item.id + "</td>\n" +
                    "       <td>" + item.productname + "</td>\n" +
                    "       <td>" + item.productid + "</td>\n" +
                    "       <td>" + item.productdescribe + "</td>\n" +
                    "       <td>" + item.amount + "</td>\n" +
                    "       <td><span class='residualamount'>" + item.residualamount + "</span> </td>\n" +
                    "       <td>" + item.amountunit + "</td>\n" +
                    "       <td>" + item.costprice + "</td>\n" +
                    "       <td><input class='ShuLiang' type='number' value='0' /></td>\n" +
                    "       </tr>"
            })
            let table = tr + tr1;
            $("#tableAdd").html(table)
        }
    })
}

function yl() {
    let residualamount =[];
    $(".residualamount").each(function () {
        residualamount.push(parseInt($(this).text()));
    })
    let shu =[];
    $(".ShuLiang").each(function () {
        shu.push(parseInt($(this).val()));
    })
    for (let l = 0; l < shu.length; l++) {
        if (shu[l]<0) {
            alert("本工序数量不能小于0！");
            return;
        }
    }
    for (let i=0;i<residualamount.length;i++){
        if (residualamount[i]<shu[i]){
            alert("本工序数量不能大于可用数量！")
            return;
        }
    }
    localStorage.setItem("shuliangList",JSON.stringify(shu));
    location.href="../../li_meng/WuLiaoSheJiDan(3).html";
}
